package com.lei.zjs.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.lei.zjs.dao.FunctionDao;
import com.lei.zjs.dao.base.BaseDaoImpl;
import com.lei.zjs.vo.Function;

@Repository
public class FunctionDaoImpl extends BaseDaoImpl<Function> implements FunctionDao {

	@Override
	public List<Function> findByUser(String userId) {
		String hql = "from Function f left outer join fetch f.roles r left outer join fetch r.users u where u.id = ?";
		return this.getHibernateTemplate().find(hql, userId);
	}

	@Override
	public List<Function> findMenu() {
		String hql = "from Function where generatemenu = '1' order by zindex";
		return this.getHibernateTemplate().find(hql);
	}

	@Override
	public List<Function> findMenuByUser(String userId) {
		String hql = "select distinct f from Function f left outer join fetch f.roles r left outer join"
				+ " fetch r.users u where u.id = ? and f.generatemenu = '1' order by zindex";
		return this.getHibernateTemplate().find(hql,userId);
	}

}
